import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// 朋友圈 - 编辑文案页 - 右上角的发表按钮
class PublishButton extends StatelessWidget {
  final ValueListenable<String> textNotifier;

  const PublishButton({
    super.key,
    required this.textNotifier,
  });

  void _publishArticle() {
    final text = textNotifier.value;
    // 发表文章的逻辑
    debugPrint('发表文章: $text');
  }

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<String>(
      valueListenable: textNotifier,
      builder: (context, text, child) {
        return ElevatedButton(
          style: ButtonStyle(
            // backgroundColor: WidgetStateProperty.all(Colors.blue),
            backgroundColor: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
              if (states.contains(WidgetState.disabled)) {
                return Colors.grey;
              } else {
                return Colors.blue;
              }
            }),
          ),
          onPressed: text.isEmpty ? null : _publishArticle,
          child: const Text('发表', style: TextStyle(color: Colors.white),),
        );
      },
    );
  }
}